
package de.dtools.n2g.search;

/**
 *	@project:	note2go
 *	@author:	D.Toepel
 *	@version:	2009-08-04
 *	@note:		---
 *	
 *	Copyright (C) 2009  D.Toepel <de.dtools> {at} <gmail> {dot} <com>
 *	
 *	This program is free software: you can redistribute it and/or modify
 *	it under the terms of the GNU General Public License as published by
 *	the Free Software Foundation, either version 3 of the License, or
 *	(at your option) any later version.
 *	
 *	This program is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *	GNU General Public License for more details.
 *	
 *	You should have received a copy of the GNU General Public License
 *	along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *	
 */

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

/**
 * 
 * @author daniel
 *
 */
public class Search extends JPanel{
	
	private static final long serialVersionUID = 1L;
	private JPanel searchGrid;
	private JTextPane titleSearch;
	private JLabel labelSearch;
	private JTextField searchField;
	private JPanel btnPanel;
	private JRadioButton rbID;
	private JRadioButton rbTag;
	private JRadioButton rbAll;
	private JButton btnSearch;
	private int toggleState;
	private String searchText;

	
	public Search(){
		super();				
	}
	
	public void setSearchButton(JButton btnSearch){
		this.btnSearch = btnSearch;
		initGUI();
	}
	
	public Integer getToggleState(){
		return this.toggleState;
	}
	
	public String getSearchText(){
		return this.searchText;
	}
	
	
	
	private void initGUI(){
		try {
			GridBagConstraints c = new GridBagConstraints();
			
			this.setLayout(new BorderLayout());
//			this.setPreferredSize(new java.awt.Dimension(600, 459));
			this.setBackground(new java.awt.Color(255,255,255));
			{
				searchGrid = new JPanel(new GridBagLayout());
				searchGrid.setBackground(new java.awt.Color(255,255,255));
				{
					titleSearch = new JTextPane();
					titleSearch.setFont(new java.awt.Font("Verdana",1,12));
					titleSearch.setContentType("text/html");
					titleSearch.setMargin(new Insets(0, 0, 0, 0));
					titleSearch.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
					titleSearch.setEditable(false);
					titleSearch.setText("<h3>:: Note2Go :: Elektronische Merkzettel</h3><hr />");
					{
						c.weightx = 0.5;
			        	c.fill = GridBagConstraints.HORIZONTAL;
			        	c.gridx = 0;
			        	c.gridwidth = 4;
			        	c.gridy = 0;
						searchGrid.add(titleSearch, c);
					}
					titleSearch = new JTextPane();
					titleSearch.setFont(new java.awt.Font("Verdana",0,12));
					titleSearch.setContentType("text/html");
					titleSearch.setMargin(new Insets(0, 0, 0, 0));
					titleSearch.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
					titleSearch.setEditable(false);
					titleSearch.setText(
							"<p>Mit Note2Go werden Textsequenzen erstellt, " +
							"die aus den unterschiedlichsten Lebenslagen heraus entstehen koennen. " +
							"Mit Hilfe so genannter Tags bzw. Labels, werden die Textausschnitte " +
							"schnell, einfach und uebersichtlich sortiert.</p>" +
							"<p>Des Weiteren ist eine Volltextsuche integriert. D.h., es wird auch " +
							"innerhalb des Textes nach den Suchbegriffen gesucht. Die ermittelten " +
							"Eintraege werden dann auf einer \"Suchergebnis\"-Seite dargestellt.</p>" +
							"<p>&nbsp;</p>");
					{
						c.weightx = 0.5;
			        	c.fill = GridBagConstraints.HORIZONTAL;
			        	c.gridx = 0;
			        	c.gridwidth = 4;
			        	c.gridy = 1;
						searchGrid.add(titleSearch, c);
					}
					titleSearch = new JTextPane();
					titleSearch.setFont(new java.awt.Font("Verdana",1,12));
					titleSearch.setContentType("text/html");
					titleSearch.setMargin(new Insets(0, 0, 0, 0));
					titleSearch.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
					titleSearch.setEditable(false);
					titleSearch.setText("<h3>Eintraege mit Hilfe von Suchbegriffen finden.</h3><hr /><br />");
					{
						c.weightx = 0.5;
			        	c.fill = GridBagConstraints.HORIZONTAL;
			        	c.gridx = 0;
			        	c.gridwidth = 4;
			        	c.gridy = 2;
						searchGrid.add(titleSearch, c);
					}
					labelSearch = new JLabel("Suche :");
					{
						c.weightx = 0;
			        	c.fill = GridBagConstraints.NONE;
			        	c.gridx = 0;
			        	c.gridwidth = 1;
			        	c.gridy = 3;
						searchGrid.add(labelSearch, c);
					}
					searchField = new JTextField();
					searchField.addKeyListener(new KeyListener() {

						@Override
						public void keyTyped(KeyEvent arg0) {}
						
						@Override
						public void keyReleased(KeyEvent arg0) {
							searchText = searchField.getText();
						}
						
						@Override
						public void keyPressed(KeyEvent arg0) {}
					});
					{
						c.weightx = 0;
			        	c.fill = GridBagConstraints.BOTH;
			        	c.gridx = 1;
			        	c.gridwidth = 3;
			        	c.gridy = 3;
						searchGrid.add(searchField, c);
					}
					btnPanel = new JPanel();
					btnPanel.setBackground(new java.awt.Color(255,255,255));
					{
						{
//							rbLabel = new JLabel("Suche in : ");
							rbID = new JRadioButton("nur iNote-ID", false);
							rbID.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
							rbID.addActionListener(new ActionListener() {
				            	public void actionPerformed(ActionEvent evt) {
				            		toggleState = -1;
				    			}
				    		});
							rbTag = new JRadioButton("nur in Tags", false);
							rbTag.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
							rbTag.addActionListener(new ActionListener() {
				            	public void actionPerformed(ActionEvent evt) {
				            		toggleState = 1;
				    			}
				    		});
							rbAll = new JRadioButton("ueberall    ", true);
							rbAll.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
							rbAll.addActionListener(new ActionListener() {
				            	public void actionPerformed(ActionEvent evt) {
				            		toggleState = 0;
				    			}
				    		});
							btnSearch.setText("Suchen");// = new JButton("Suchen");
						}
						{
							ButtonGroup selectSearch = new ButtonGroup();
							selectSearch.add(rbID);
							selectSearch.add(rbTag);
							selectSearch.add(rbAll);
						}
//						btnPanel.add(rbLabel);
						btnPanel.add(rbID);
						btnPanel.add(rbTag);
						btnPanel.add(rbAll);
						btnPanel.add(btnSearch);
						{
							c.weightx = 0;
				        	c.fill = GridBagConstraints.NONE;
				        	c.gridx = 1;
				        	c.gridwidth = 3;
				        	c.gridy = 4;
							searchGrid.add(btnPanel, c);
						}
					}
				}
				this.add(searchGrid, BorderLayout.NORTH);
			}
		} catch (Exception e) {
			//
		}
	}

}
